using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-09
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 故障日志
    /// </summary>
    [Verify]
    [Route("business/FaultLog")]
    [ApiExplorerSettings(GroupName = "business")]
    public class FaultLogController : BaseController
    {
        /// <summary>
        /// 故障日志接口
        /// </summary>
        private readonly IFaultLogService _FaultLogService;

        public FaultLogController(IFaultLogService FaultLogService)
        {
            _FaultLogService = FaultLogService;
        }

        /// <summary>
        /// 查询故障日志列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "faultlog:list")]
        public IActionResult QueryFaultLog([FromQuery] FaultLogQueryDto parm)
        {
            var response = _FaultLogService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询故障日志详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "faultlog:query")]
        public IActionResult GetFaultLog(long Id)
        {
            var response = _FaultLogService.GetInfo(Id);
            
            var info = response.Adapt<FaultLogDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加故障日志
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "faultlog:add")]
        [Log(Title = "故障日志", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFaultLog([FromBody] FaultLogDto parm)
        {
            var modal = parm.Adapt<FaultLog>().ToCreate(HttpContext);

            var response = _FaultLogService.AddFaultLog(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新故障日志
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "faultlog:edit")]
        [Log(Title = "故障日志", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFaultLog([FromBody] FaultLogDto parm)
        {
            var modal = parm.Adapt<FaultLog>().ToUpdate(HttpContext);
            var response = _FaultLogService.UpdateFaultLog(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除故障日志
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "faultlog:delete")]
        [Log(Title = "故障日志", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFaultLog([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_FaultLogService.Delete(idArr));
        }

    }
}